// 鼠标移动和点击到建筑改变颜色
export default (viewer) => {
    // 用来存储选中的建筑信息
    var selected = {
        feature: undefined,
        originalColor: new Cesium.Color(),
    }
    // 一个实体对象保存当前选中的信息供信息框显示
    var selectedEntity = new Cesium.Entity();
    // 处理点击到空白处的事件
    var cilckHandler = viewer.screenSpaceEventHandler.getInputAction(
        Cesium.ScreenSpaceEventType.LEFT_CLICK
    );
    // 判断当前浏览器是否支持
    if (Cesium.PostProcessStageLibrary.isSilhouetteSupported(viewer.scene)) {
        // var silhoutteBlue = Cesium.PostProcessStageLibrary.createEdgeDetectionStage();
        // silhoutteBlue.uniforms.color = Cesium.Color.BLUE;
        // silhoutteBlue.uniforms.length = 0.01;
        // silhoutteBlue.selected = [];

        var silhoutteGreen = Cesium.PostProcessStageLibrary.createEdgeDetectionStage();
        silhoutteGreen.uniforms.color = Cesium.Color.LIME;
        silhoutteGreen.uniforms.length = 0.02;
        silhoutteGreen.selected = [];

        viewer.scene.postProcessStages.add(
            Cesium.PostProcessStageLibrary.createSilhouetteStage([
                // silhoutteBlue,
                silhoutteGreen
            ])
        )
        // // 添加鼠标移动时的蓝色框
        // viewer.screenSpaceEventHandler.setInputAction(function onMouseMove(
        //     movement
        // ) {
        //     silhoutteBlue.selected = [];
        //     var pickedFeature = viewer.scene.pick(movement.endPosition);
        //     if (pickedFeature != selected.feature) {// 在建筑没有被选中时外框为蓝色
        //         silhoutteBlue.selected = [pickedFeature]
        //     }
        // }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

        // 添加点击时的绿色框
        viewer.screenSpaceEventHandler.setInputAction(function onClick(movement) {
            silhoutteGreen.selected = [];
            var pickedFeature = viewer.scene.pick(movement.position);
            if (!Cesium.defined(pickedFeature)) {// 判断是否选择为空
                cilckHandler(movement);
                return;
            }
            if (silhoutteGreen.selected[0] === pickedFeature) {// 点击处为当前选中项
                return
            }
            // var highlightedFeature = silhoutteBlue.selected[0];
            // if (pickedFeature === highlightedFeature) {// 将移动变成蓝色的建筑取消蓝色显示
            //     silhoutteBlue.selected = [];
            // }
            silhoutteGreen.selected = [pickedFeature];// 添加绿色外框
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
    }
    else { alert('您的浏览器暂不支持选中功能，请使用谷歌浏览器') }
}